stylecontext: Don't crah when invalidate() is called on saved context
authorBenjamin Otte <otte@redhat.com>
Wed, 4 Feb 2015 20:08:54 +0000 (21:08 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 4 Feb 2015 20:20:29 +0000 (21:20 +0100)
We need to invalidate the root node, not the current one.
Fixes crashes on startup of eclipse.

Testcase included.

https://bugzilla.redhat.com/show_bug.cgi?id=1185828

gtk/gtkstylecontext.c
testsuite/gtk/stylecontext.c

index 941410f9a85e93b66c76c482e8ea78e86e57f772..959857dc3818497f973253af199842b98f03e845 100644 (file)
@@ -3108,17 +3108,19 @@ gtk_style_context_invalidate (GtkStyleContext *context)
 {
   GtkBitmask *changes;
   GtkCssStyle *style;
+  GtkCssNode *root;
 
   g_return_if_fail (GTK_IS_STYLE_CONTEXT (context));
 
   gtk_style_context_clear_cache (context);
+  gtk_css_node_set_values (context->priv->cssnode, NULL);
 
-  /* insta-recalculate the new style here */
+  root = gtk_style_context_get_root (context);
   style = build_properties (context,
-                            context->priv->cssnode->decl,
-                            !gtk_style_context_is_saved (context),
-                            gtk_css_node_get_parent_style (context, context->priv->cssnode));
-  gtk_css_node_set_values (context->priv->cssnode, style);
+                            root->decl,
+                            TRUE,
+                            gtk_css_node_get_parent_style (context, root));
+  gtk_css_node_set_values (root, style);
   g_object_unref (style);
 
   if (!gtk_style_context_is_saved (context))
index 55bd2c754f8134cf9046950759893178aff1a883..9ed3b58f1e2545b9e06fe59df3cb32541a7555fa 100644 (file)
@@ -289,6 +289,24 @@ test_basic_properties (void)
   g_object_unref (context);
 }
 
+void
+test_invalidate_saved (void)
+{
+  GtkWidget *window;
+  GtkStyleContext *context;
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+  context = gtk_widget_get_style_context (window);
+  gtk_style_context_save (context);
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  gtk_style_context_invalidate (context);
+G_GNUC_END_IGNORE_DEPRECATIONS
+  gtk_style_context_restore (context);
+
+  gtk_widget_destroy (window);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -299,6 +317,7 @@ main (int argc, char *argv[])
   g_test_add_func ("/style/path", test_path);
   g_test_add_func ("/style/match", test_match);
   g_test_add_func ("/style/basic", test_basic_properties);
+  g_test_add_func ("/style/invalidate-saved", test_invalidate_saved);
 
   return g_test_run ();
 }